package hn.sigit.model.hnd.ladmshadow;

import hn.sigit.model.ladm.party.LA_GroupPartyType;

import java.io.Serializable;
import javax.persistence.*;


@Entity
@org.hibernate.annotations.Proxy(lazy=false)
@Table(name="GroupParty", schema="ladmshadow")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorValue("GroupParty")
@PrimaryKeyJoinColumn(name="PartyID", referencedColumnName="ID")
public class GroupParty extends Party implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private LA_GroupPartyType groupPartyType;
	private java.util.Set<PartyMember> partymembers = new java.util.HashSet<PartyMember>();
	
	public GroupParty() {
	}
	
	@Column(name="GroupPartyType", nullable=true)
	@Enumerated(EnumType.STRING)
	public LA_GroupPartyType getGroupPartyType() {
		return groupPartyType;
	}
	public void setGroupPartyType(LA_GroupPartyType value) {
		this.groupPartyType = value;
	}
	
	@OneToMany(mappedBy="groupparty", targetEntity=PartyMember.class)	
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})	
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.TRUE)	
	public java.util.Set<PartyMember> getpartymembers() {
		return partymembers;
	}
	public void setpartymembers(java.util.Set<PartyMember> value) {
		this.partymembers = value;
	}
	
	@Transient
	public Party[] getpartys() {
		java.util.ArrayList lValues = new java.util.ArrayList(5);
		for(java.util.Iterator lIter = partymembers.iterator();lIter.hasNext();) {
			lValues.add(((PartyMember)lIter.next()).getparty());
		}
		return (Party[])lValues.toArray(new Party[lValues.size()]);
	}
	
	public void removeparty(Party aparty) {
		PartyMember[] lpartymembers = (PartyMember[])partymembers.toArray(new PartyMember[partymembers.size()]);
		for(int i = 0; i < lpartymembers.length; i++) {
			if(lpartymembers[i].getparty().equals(aparty)) {
				partymembers.remove(lpartymembers[i]);
			}
		}
	}
	
	public void addparty(PartyMember aPartyMember, Party aparty) {
		aPartyMember.setparty(aparty);
		partymembers.add(aPartyMember);
	}
	
	public PartyMember getpartymemberByparty(Party aparty) {
		PartyMember[] lpartymembers = (PartyMember[])partymembers.toArray(new PartyMember[partymembers.size()]);
		for(int i = 0; i < lpartymembers.length; i++) {
			if(lpartymembers[i].getparty().equals(aparty)) {
				return lpartymembers[i];
			}
		}
		return null;
	}
	
	public String toString() {
		return super.toString();
	}
	
}
